<?php
/**
 * Created by YuanXiShop.
 * User: YuanXi
 * Date: 2021/6/1 0001
 * Time: 16:39
 */

if(!function_exists('dd'))
{
    function dd(...$args)
    {
        http_response_code(500);
        foreach ($args as $x)
        {
            var_dump($x);
        }
        die();
    }
}

function getCurUrl()
{
    $url = "http://";
    if(isset($_SERVER['SERVER_HTTPS']) && $_SERVER['SERVER_HTTPS'] == 'on'){
        $url = "https://";
    }
    //判断端口
    if($_SERVER['SERVER_PORT'] != '80'){
        $url .= $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
    }else{
        $url .= $_SERVER['SERVER_NAME'];
    }
    return $url;
}
function ew_login($utype)
{
    // return 1;
    // dd($_SESSION['id'].$_SERVER['HTTP_HOST'],$_SESSION[$utype.'_token'],$_SESSION['id']);
    return md5($_SESSION['id'].$_SERVER['HTTP_HOST']) == $_SESSION[$utype.'_token'] ? 1 : 0;
}

//获取用户IP， 定义一个函数getIP()
function getClientIP(){
    if (getenv("HTTP_CLIENT_IP")) {
        $ip = getenv("HTTP_CLIENT_IP");
    }elseif(getenv("HTTP_X_FORWARDED_FOR")) {
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    }elseif(getenv("REMOTE_ADDR")) {
        $ip = getenv("REMOTE_ADDR");
    }else{
        $ip = "Unknow";
    }
    return $ip;
}

